#include "Game_LengthenFrame.h"

#include "../Game.h"
#include "../GameControl.h"
#include "../../tools/Log.h"

#include <cstring>

string Game_LengthenFrame::command = "lengthen frame";

string Game_LengthenFrame::toString() { return string(serialize().data); }

SerializedGameCommand Game_LengthenFrame::serialize() const
{
	SerializedGameCommand cmd;
	sprintf(cmd.data, "%s %lu", command.c_str(), timestamp);
	return cmd;
}

Game_LengthenFrame* Game_LengthenFrame::interpret(const SerializedGameCommand& sgc)
{
	if (strncmp(sgc.data, command.c_str(), command.size()) == 0)
	{
		Game_LengthenFrame* cmd = new Game_LengthenFrame();
		if(sscanf(sgc.data, "lengthen frame %lu", &(cmd->timestamp)) == 1)
			return cmd;
	}
	
	return NULL;
}

Game_LengthenFrame* Game_LengthenFrame::interpret(const char* line)
{
	if (strncmp(line, command.c_str(), command.size()) == 0)
	{
		Game_LengthenFrame* cmd = new Game_LengthenFrame();
		if(sscanf(line, "lengthen frame %lu", &(cmd->timestamp)) == 1)
			return cmd;
		else if(sscanf(line, "lengthen frame") == 0)
			return cmd;
		
		lout << Game_LengthenFrame::command << " error: Invalid arguments" << endl;
		delete cmd;
	}
	
	return NULL;
}

void Game_LengthenFrame::onExecute()
{
	// -- BEGIN CUSTOM CODE REGION -- //
	GameControl::Instance()->increase_frame_length();
	// -- END CUSTOM CODE REGION -- //
}
